<template>
	<!-- 总容器 -->
	<div class="wrapper">
	  <!-- header部分 -->
	  <header>
		<p>更新点餐类型</p>
	  </header>
  
	  <!-- 更新点餐类型部分 -->
	  <div class="form-box">
		<li>
		  <div class="title">餐品类型:</div>
		  <div class="content" style="font-size: 3vw;">
			<input type="radio" v-model="newTypeId" value="1" style="width:6vw;height: 3.2vw;">美食
			<input type="radio" v-model="newTypeId" value="2" style="width:6vw;height: 3.2vw;">早餐
			<input type="radio" v-model="newTypeId" value="3" style="width:6vw;height: 3.2vw;">跑腿代购
			<input type="radio" v-model="newTypeId" value="4" style="width:6vw;height: 3.2vw;">汉堡披萨
			<input type="radio" v-model="newTypeId" value="5" style="width:6vw;height: 3.2vw;">甜品饮品
			<input type="radio" v-model="newTypeId" value="6" style="width:6vw;height: 3.2vw;">速食简餐
			<input type="radio" v-model="newTypeId" value="7" style="width:6vw;height: 3.2vw;">地方小吃
			<input type="radio" v-model="newTypeId" value="8" style="width:6vw;height: 3.2vw;">米粉面馆
			<input type="radio" v-model="newTypeId" value="9" style="width:6vw;height: 3.2vw;">包子粥铺
			<input type="radio" v-model="newTypeId" value="10" style="width:6vw;height: 3.2vw;">炸鸡炸串
		  </div>
		</li>
	  </div>
  
	  <!-- 保存按钮 -->
	  <div class="save-button">
		<button @click="toUpdateOrderTypeId">保存</button>
	  </div>
  
	  <!-- 底部菜单部分 -->
	  <BusinessFooter />
	</div>
  </template>
  
  <script setup>
  import { ref, onMounted } from 'vue';
  import axios from 'axios';
  import BusinessFooter from '../components/BusinessFooter.vue';
  
  // 定义响应式变量
  const newTypeId = ref('');
  const business = ref({
	businessId: '',
	businessName: '',
	businessAddress: '',
	businessExplain: '',
	orderTypeId: '',
	starPrice: '',
	deliveryPrice: '',
	remarks: '',
	password: ''
  });
  
  // 生命周期钩子，在组件挂载时从 sessionStorage 获取商家信息
  onMounted(() => {
	const storedBusiness = JSON.parse(sessionStorage.getItem('business'));
	if (storedBusiness) {
	  business.value = storedBusiness;
	}
  });
  
  // 更新点餐类型方法
  const toUpdateOrderTypeId = async () => {
	if (!newTypeId.value) {
	  alert('更新点餐类型不能为空！');
	  return;
	}
  
	business.value.orderTypeId = newTypeId.value;
  
	try {
	  const response = await axios.put('/Business', new URLSearchParams(business.value));
	  if (response.data > 0) {
		sessionStorage.setItem('business', JSON.stringify(business.value));
		alert('修改更新点餐类型成功！');
	  } else {
		alert('修改更新点餐类型失败！');
	  }
	} catch (error) {
	  console.error('更新点餐类型时出错:', error);
	  alert('出现错误！');
	}
  };
  </script>
  
  <style scoped>
  /****************** 总容器 ******************/
  .wrapper {
	width: 100%;
	height: 100%;
  }
  
  /****************** header ******************/
  .wrapper header {
	width: 100%;
	height: 12vw;
	background-color: #0097ff;
	color: #fff;
	font-size: 4.8vw;
	position: fixed;
	left: 0;
	top: 0;
	z-index: 1000;
	display: flex;
	justify-content: center;
	align-items: center;
  }
  
  /****************** 修改点餐类型部分 ******************/
  .wrapper .form-box {
	width: 100%;
	padding-top: 12vw;
  }
  
  .wrapper .form-box li {
	display: flex;
	align-items: center;
	box-sizing: border-box;
	padding: 3vw 3vw 0;
  }
  
  .wrapper .form-box li .title {
	flex: 0 0 18vw;
	font-size: 3.5vw;
	font-weight: 700;
	color: darkslategray;
  }
  
  .wrapper .form-box li .content {
	flex: 1;
  }
  
  .wrapper .form-box li .content input {
	width: 100%;
	box-sizing: border-box;
	padding: 4vw 2vw;
	border-radius: 3vw;
	background-color: white;
	font-size: 3vw;
	border: none;
	outline: none;
  }
  
  /****************** 保存按钮部分 ******************/
  .wrapper .save-button {
	width: 100%;
	box-sizing: border-box;
	padding: 4vw 10vw 0;
  }
  
  .wrapper .save-button button {
	width: 100%;
	height: 10vw;
	background-color: mediumseagreen;
	border: none;
	outline: none;
	border-radius: 4vw;
	font-size: 3.5vw;
	color: white;
	cursor: pointer;
  }
  </style>
  